package com.hi.hiparty.util;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;

public class JSONResponseHelper {

	public static void sendJSONResult(HttpServletResponse response, JSONObject result,
			String callback) throws IOException {
		if (StringUtils.isBlank(callback)) {
			response.setContentType("application/json;charset=UTF-8");
			response.getWriter().print(result.toString());
		} else {
			response.setContentType("text/javascript;charset=UTF-8");
			response.getWriter()
					.print(callback + "(" + result.toString() + ")");
		}
	}

}
